home *** CD-ROM | disk | FTP | other *** search
- ;void set_mem_8(replacement,position,bits,segment,offset);
- ; unsigned char replacement,position,bits;
- ; unsigned short segment,offset;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _set_mem_8
- _set_mem_8 proc near
- push bp ;
- mov bp,sp ;make stack frame
- push di ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: mov _error_code,0 ;clear _error_code
- les di,dword ptr[bp+12] ;ES:DI pts to memory
- mov cl,[bp+8] ;number bits
- inc _error_code ;1 = zero bits
- or cl,cl ;error check
- jz L1 ;quit if zero bits
- mov dl,0FFH ;all 1s in DL
- shl dl,cl ;field-width of 0s
- not dl ;field-width of 1s
- mov al,[bp+4] ;replacement value
- and al,dl ;clear superfluous bits
- mov bl,cl ;copy Bits to BL
- mov cl,[bp+6] ;Position
- inc _error_code ;2 = position out of range
- cmp cl,7 ;greater than 7?
- ja L1 ;quit if so
- add bl,cl ;add number bits
- inc _error_code ;3 = field too large
- cmp bl,8 ;does it fit?
- ja L1 ;quit if error
- shl al,cl ;shift value to position
- shl dl,cl ;shift mask to position
- not dl ;reverse mask
- and es:[di],dl ;clear field
- or es:[di],al ;write new bits
- mov _error_code,0 ;success, return 0
- L1: pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _set_mem_8 endp
- _TEXT ENDS
- END